<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="../../resources/home/css/css.css" rel="stylesheet" type="text/css" />
<link href="../../resources/home/css/common.css" rel="stylesheet" tyle="text/css" />
<link href="../../resources/home/css/Orders.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="../../resources/admin/easyui/easyui/1.3.4/themes/default/easyui.css" />
<link rel="stylesheet" type="text/css" href="../../resources/admin/easyui/css/wu.css" />
<link rel="stylesheet" type="text/css" href="../../resources/admin/easyui/css/icon.css" />
<script src="../../resources/home/js/jquery-1.9.1.min.js" type="text/javascript"></script>
<script src="../../resources/home/js/jquery.reveal.js" type="text/javascript"></script>
<script src="../../resources/home/js/jquery.SuperSlide.2.1.1.js" type="text/javascript"></script>
<script src="../../resources/home/js/jquery.sumoselect.min.js" type="text/javascript"></script>
<script src="../../resources/home/js/common_js.js" type="text/javascript"></script>
<script src="../../resources/home/js/footer.js" type="text/javascript"></script>
<script src="../../resources/home/js/jquery.jumpto.js" type="text/javascript"></script>
<script type="text/javascript" src="../../resources/admin/easyui/js/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="../../resources/admin/easyui/easyui/1.3.4/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../../resources/admin/easyui/easyui/1.3.4/locale/easyui-lang-zh_CN.js"></script>
<title>确认订单界面</title>
</head>
<script>
var charCount;
$(function() {
	$("#remark").val("");
});
function CountWords(obj, show_id){ 
 
 var fullStr = obj.value; 
 charCount = fullStr.length;

 var rExp = /[^A-Za-z0-9]/gi; 
 var spacesStr = fullStr.replace(rExp, ' '); 
 var cleanedStr = spacesStr + ' '; 
 do{ 
  var old_str = cleanedStr; 
  cleanedStrcleanedStr = cleanedStr.replace(' ', ' '); 
 }while( old_str != cleanedStr ); 
  var splitString = cleanedStr.split(' '); 
  document.getElementById(show_id).innerHTML=charCount; 
} 

function submit_order()
{
	

	<c:if test="${address == null}">
		$.messager.alert("消息提醒", "您还未添加地址，请先去个人中心添加地址！", "info",function(){window.location.href="/TeaShop/home/account/address";});
		return;
	</c:if>
	
	
	var total_Price = $('#total_Price').val();
	$.messager.confirm("消息提醒", "本次消费：<font color=red>"+total_Price+"</font>元，确定支付吗？", function (data) {
        if (data) {

        	if(charCount>50)
        	{
        		$.messager.alert("消息提醒","备注字数不能大于50字！", "warning");
        		return;
        	}
        	
        	var cart_id = "";
        	<c:forEach items="${cartList}" var="cart" varStatus="vs">
        		cart_id += ",${cart.id}";    //,2,3
        	</c:forEach>
        		
        
        	var remark = $('#remark').val();
        		
        	$.ajax({
        		type: "post",
        		url: "/TeaShop/home/shopping/submit_order",
        		data: {cart_id:cart_id,remark:remark}, 
        		dataType: "json", //返回数据类型
        		success: function(result){
        			if(result.type == 'success'){
        				$.messager.alert("消息提醒", result.msg, "info",function(){window.location.href="/TeaShop/home/system/index";});
        			}
        			else{
        				$.messager.alert("消息提醒", result.msg, "warning");
        			}
        			
        		}
        		
        	});
        		
        		
        		
        }
        else {
        	return;
        }
    });
	
	
	
	
	
}

</script>
<body>
<%@include file="../common/common_top.jsp"%>
<!--导航栏样式-->
<div id="Menu" class="clearfix">
<div class="Menu_style">
  <div id="allSortOuterbox" class="display">
    <div class="Category"><a href="/TeaShop/home/product/list" class="Menu_img"><em></em></a></div>
    <div class="hd_allsort_out_box_new">
	 <!--左侧栏目开始-->
	 <div class="Menu_list">	
	    <div class="menu_title">茶叶品种</div>
        <c:forEach items="${teaCategoryList}" var="teaCategory">
				<a href="${teaCategory.href}">${teaCategory.name}</a>
			</c:forEach>
	</div>	
    <div class="Menu_list">	
	    <div class="menu_title">茶叶价格</div>
        <a href="/TeaShop/home/product/list?price=1">100以下</a><a href="/TeaShop/home/product/list?price=2">100-200</a>
        <a href="/TeaShop/home/product/list?price=3">200-400</a><a href="/TeaShop/home/product/list?price=4">400-600</a>
        <a href="/TeaShop/home/product/list?price=5">600-1000</a><a href="/TeaShop/home/product/list?price=6">1000以上</a>
	</div>	
     <div class="Menu_list">	
	    <div class="menu_title">推荐茶叶</div>
        <ul class="recommend">
        	<c:set var="count" value="0"></c:set>
            <c:forEach items="${teaListByActionId}" var="tea">
               		<!-- 只允许显示2个 -->
               		<c:if test="${count < 2}">
	         			 	<li><a href="${tea.href}" title="${tea.name}">${tea.name}</a></li>
	               		  	<c:set var="count" value="${count+1}"></c:set>
         			</c:if>
         	</c:forEach>
        </ul>
	</div>	
	</div>		
	</div>
     <div class="Navigation" id="Navigation">
		 <ul class="Navigation_name">
			<li><a class="nav_on" id="mynav"  href="/TeaShop/home/system/index"><span>首页</span></a></li>
			 <c:forEach items="${teaCategoryList}" var="teaCategory">
				<li><a class="nav_on" id="mynav"  href="${teaCategory.href}"><span>${teaCategory.name}</span></a></li>
			 </c:forEach>
		 </ul>			 
	 </div>
    <!--购物车-->	 
     <div class="hd_Shopping_list" id="Shopping_list">
   <div class="s_cart"><em></em><a href="#">我的购物车</a> <i class="ci-right">&gt;</i><i class="ci-count" id="shopping-amount">${cartTotal}</i></div>
   <div class="dorpdown-layer">
    <div class="spacer"></div>
	 <!--<div class="prompt"></div><div class="nogoods"><b></b>购物车中还没有商品，赶紧选购吧！</div>-->
	 <ul class="p_s_list">	   
		
	 	 <c:set var="totalPrice" value="0"></c:set>
 		 <c:forEach items="${cartList}" var="cart" varStatus="vs">
			  <li>
			    <div class="img"><img src="${cart.tea.photo}" style="width:40px;height:40px;"></div>
			    <div class="content">
			      <p><a href="${cart.tea.href}">${cart.tea.name}</a></p><p>${cart.tea.info}</p>
			    </div>
				<div class="Operations">
				<p class="Price">￥${cart.tea.new_price}</p>
				<p>数量：${cart.num}</p></div>
			  </li>
			   <c:set var="totalPrice" value="${totalPrice+cart.tea.new_price*cart.num}"></c:set>
		 </c:forEach>
		</ul>		
	 <div class="Shopping_style">
	<div class="p-total">共<b>${cartTotal}</b>件商品　共计<strong>￥ ${totalPrice}</strong></div>
	  <a href="/TeaShop/home/shopping/cart" title="去购物车结算" id="btn-payforgoods" class="Shopping">去购物车结算</a>
	 </div>	 
   </div>	
  </div>
</div>
</div>
<div id="Orders" class="Inside_pages  clearfix">
  <div class="Orders_style clearfix">
     <div class="address clearfix">
       <div class="title">收货人信息</div>
          <div class="adderss_list clearfix">
            <div class="title_name">选择收货地址 <a href="/TeaShop/home/account/address">+添加地址</a></div>

     <div class="Shipping_address">
       <ul class="detailed">
        <li><label>收货人姓名</label><span>${address.name}</span></li>
        
        <li><label>详细地址</label><span>${address.province}${address.city}${address.area}${address.detail}</span></li>
        <li><label>邮政编码</label><span>${address.postcode}</span></li>
        <li><label>收货人手机</label><span>${address.phone}</span></li> 
       
       </ul>
     </div>
     </div> 
        
     <form class="form" id="order_form" method="post">  
		<fieldset> 

     <!--产品列表-->
     <div class="Product_List">

      <table>
       <thead><tr class="title"><td class="name">商品名称</td><td class="price">商品原价</td><td class="Preferential">商品新价</td><td class="Quantity">购买数量</td><td class="Money">金额</td></tr></thead>
       <tbody>
       	 <c:set var="totalPrice" value="0"></c:set>
	     <c:forEach items="${cartList}" var="cart" varStatus="vs">
		   <tr>
	        <td class="Product_info">
	         <a href="${cart.tea.href}"><img src="${cart.tea.photo}"  width="100px" height="100px"/></a>
	         <a href="${cart.tea.href}" class="product_name">${cart.tea.name}</a>
	         </td>
	        <td><i>￥</i>${cart.tea.pre_price}</td>
	        <td><i>￥</i>${cart.tea.new_price}</td>
	        <td>${cart.num}</td>
	        <td class="Moneys"><i>￥</i>${cart.tea.new_price * cart.num}</td>
	       </tr>
	        <c:set var="totalPrice" value="${totalPrice+cart.tea.new_price * cart.num}"></c:set>
		  </c:forEach>
     
       
       </tbody>
      </table>
      <div class="Pay_info">
       <label>订单留言</label><input id ="remark" name="remark" type="text"   onkeyup="CountWords(this,'show')" class="text_name " />  <span class="wordage" >字数：<span id="show" style="color:Red;">0</span>/50</span>  
      </div>
      <!--价格-->
      <div class="price_style">
      <input id="total_Price" type="hidden" value="${totalPrice}" />
      <div class="right_direction">
        <ul>
         <li><label>商品总价</label><i>￥</i><span>${totalPrice}</span></li>
        
        
         <li class="shiji_price"><label>实&nbsp;&nbsp;付&nbsp;&nbsp;款</label><i>￥</i><span>${totalPrice}</span></li>    
        </ul>   
        <div class="btn">
        	<input  type="button" onclick="submit_order();" value="提交订单" class="submit_btn"/>
        	<a href="/TeaShop/home/shopping/cart"><input type="button" value="返回购物车"   class="return_btn"/></a>
        </div>
         
      </div>
      </div>
     </div>  
     </fieldset>
        </form>
  </div>
</div>

</div>
<%@include file="../common/footer.jsp"%>

</body>
</html>
